package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.Teacher;
import com.ibeifeng.crm.dao.TeacherDao;

@Repository
public class TeacherDaoImpl implements TeacherDao {
	Logger log = Logger.getLogger(TeacherDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public int add(Teacher teacher) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.TeacherNS.insert", teacher);
		return result;
	}
	@Override
	public int update(Teacher teacher) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.TeacherNS.update", teacher);
		return result;
	}
	@Override
	public int delete(int [] idsdel) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.TeacherNS.delete", idsdel);
		return result;
	}
	@Override
	public Teacher queryTeacher(Teacher teacher) {
		Teacher tea = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.TeacherNS.findById", teacher);
		return tea;
	}
	
	
	
	Map map = new HashMap();

	@Override
	public List<Teacher> findAllSplit(int page, int pageSize, String column,
			String keyWord) {
		int start = (page-1)*pageSize;
		map.put("start", start);
		map.put("pageSize", pageSize);
		map.put("column", column);
		map.put("keyWord", keyWord);
		List<Teacher> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.TeacherNS.findAllSplit",map);
		return list;
	}
	
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.TeacherNS.getAllCount",map);
		return count;
	}
	@Override
	public List<Teacher> queryMethod() {
		List<Teacher> teachers = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.TeacherNS.getTeachers");
		return teachers;
	}
	

}
